X-Git-Url: https://git.r.bdr.sh/rbdr/super-polarity/blobdiff_plain/097781e6ad3f7bb1c13c16ff7b6bb7219764fb29..b587e9d8e0cc5eb1edf972fd3b644704441e5289:/Super%20Polarity/GameScreen.cs diff --git a/Super Polarity/GameScreen.cs b/Super Polarity/GameScreen.cs index 28fd7b7..783e3c1 100644 --- a/Super Polarity/GameScreen.cs +++ b/Super Polarity/GameScreen.cs @@ -4,6 +4,8 @@ using System.Linq; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Audio; +using Microsoft.Xna.Framework.Media; using Microsoft.Xna.Framework.Input; namespace SuperPolarity @@ -12,42 +14,196 @@ namespace SuperPolarity { public GameScreen(SuperPolarity newGame) : base(newGame) {} - private BasicGenerator generatorTest; + protected List Generators; + + protected int LivesRate; + protected int CurrentLivesRate; + protected int BombRate; + protected int CurrentBombRate; + protected SoundEffect BombSound; + protected SoundEffect LifeSound; + + protected bool Flashing; + + protected bool IsPaused; + protected Texture2D PauseScreen; public override void Initialize() { + Generators = new List(); + + CurrentBombRate = 1; + BombRate = 6000; + + LivesRate = 10000; + CurrentLivesRate = 1; + InputController.RegisterEventForButton("changePolarity", Buttons.A); InputController.RegisterEventForKey("changePolarity", Keys.Z); InputController.RegisterEventForButton("shoot", Buttons.X); InputController.RegisterEventForKey("shoot", Keys.X); + + InputController.Bind("pause", HandlePause); + + PauseScreen = Game.Content.Load("Graphics\\pause-screen"); + } + + protected void HandlePause(float value) + { + Console.WriteLine("Paused"); + IsPaused = !IsPaused; + + if (IsPaused) + { + MediaPlayer.Volume = 0.05f; + } + else + { + MediaPlayer.Volume = 1; + } } public override void LoadContent() { + CreateGenerators(); + + Vector2 playerPosition = new Vector2(Game.GraphicsDevice.Viewport.TitleSafeArea.X + Game.GraphicsDevice.Viewport.Width / 2, Game.GraphicsDevice.Viewport.TitleSafeArea.Y + Game.GraphicsDevice.Viewport.TitleSafeArea.Height / 2); - generatorTest = new BasicGenerator(); - generatorTest.Initialize(Game, new Vector2(100, 600), BasicGenerator.Ships.Scout, 3000, 10); + BombSound = Game.Content.Load("Sound\\bomb"); + LifeSound = Game.Content.Load("Sound\\life"); - Vector2 playerPosition = new Vector2(Game.GraphicsDevice.Viewport.TitleSafeArea.X, Game.GraphicsDevice.Viewport.TitleSafeArea.Y + Game.GraphicsDevice.Viewport.TitleSafeArea.Height / 2); + Renderer.CheckIn(ActorFactory.CreateMainShip(playerPosition)); - ActorFactory.CreateMainShip(playerPosition); - ActorFactory.CreateShip(Ship.Polarity.Positive, new Vector2(200, 200)); - ActorFactory.CreateShip(Ship.Polarity.Negative, new Vector2(400, 200)); - ActorFactory.CreateScout(Ship.Polarity.Negative, new Vector2(500, 500)); - ActorFactory.CreateCruiser(Ship.Polarity.Positive, new Vector2(40, 40)); + Game.PlaySong("game"); + } + + protected void CalculateBomb() + { + if (Game.Player.Score >= BombRate * CurrentBombRate) + { + ActorManager.Bomb(); + Flashing = true; + BombSound.Play(); + CurrentBombRate = CurrentBombRate + 1; + } + } + + protected void CalculateLife() + { + if (Game.Player.Score >= LivesRate * CurrentLivesRate) + { + Game.Player.Lives = Game.Player.Lives + 1; + LifeSound.Play(); + CurrentLivesRate = CurrentLivesRate + 1; + } } public override void Update(GameTime gameTime) { - InputController.UpdateInput(); + CalculateBomb(); + CalculateLife(); + InputController.UpdateInput(IsPaused); + if (IsPaused) + { + return; + } ActorManager.Update(gameTime); - generatorTest.Update(gameTime); + + foreach (BasicGenerator generator in Generators) + { + generator.Update(gameTime); + } } public override void Draw(SpriteBatch spriteBatch) { Renderer.Draw(spriteBatch); + Game.Player.Draw(spriteBatch); + + if (IsPaused) + { + spriteBatch.Draw(PauseScreen, new Vector2(0, 0), Color.White); + } + + if (Flashing) + { + Game.GraphicsDevice.Clear(Color.Black); + Flashing = false; + } + } + + protected void CreateGenerators() + { + // The basic ship generators. + var gen = new BasicGenerator(); + gen.Initialize(Game, new Vector2(-50, -50), BasicGenerator.Ships.Ship, 3000, 0); + Generators.Add(gen); + + gen = new BasicGenerator(); + gen.Initialize(Game, new Vector2(-50, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Ship, 3000, 0); + Generators.Add(gen); + + gen = new BasicGenerator(); + gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width + 50, -50), BasicGenerator.Ships.Ship, 3000, 0); + Generators.Add(gen); + + gen = new BasicGenerator(); + gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width + 50, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Ship, 3000, 0); + Generators.Add(gen); + + // After 1.5k liberate some sporadic Scouts, and add two more ship generators. + gen = new BasicGenerator(); + gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, -50), BasicGenerator.Ships.Ship, 3000, 1500); + Generators.Add(gen); + + gen = new BasicGenerator(); + gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Ship, 3000, 1500); + Generators.Add(gen); + + gen = new BasicGenerator(); + gen.Initialize(Game, new Vector2(-50, Game.GraphicsDevice.Viewport.Height / 2), BasicGenerator.Ships.Scout, 6000, 1500); + Generators.Add(gen); + + gen = new BasicGenerator(); + gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width + 50, Game.GraphicsDevice.Viewport.Height / 2), BasicGenerator.Ships.Scout, 6000, 1500); + Generators.Add(gen); + + + // After 3k add more scouts. + gen = new BasicGenerator(); + gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, -50), BasicGenerator.Ships.Scout, 3000, 3000); + Generators.Add(gen); + + gen = new BasicGenerator(); + gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Scout, 3000, 5000); + Generators.Add(gen); + + // After 5k release more ships and a cruiser. + gen = new BasicGenerator(); + gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, -50), BasicGenerator.Ships.Ship, 1500, 5000); + Generators.Add(gen); + + gen = new BasicGenerator(); + gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width / 2, Game.GraphicsDevice.Viewport.Height + 50), BasicGenerator.Ships.Ship, 1500, 5000); + Generators.Add(gen); + + gen = new BasicGenerator(); + gen.Initialize(Game, new Vector2(-50, Game.GraphicsDevice.Viewport.Height / 2), BasicGenerator.Ships.Battlecruiser, 10000, 5000); + Generators.Add(gen); + + gen = new BasicGenerator(); + gen.Initialize(Game, new Vector2(Game.GraphicsDevice.Viewport.Width + 50, Game.GraphicsDevice.Viewport.Height / 2), BasicGenerator.Ships.Battlecruiser, 10000, 5000); + Generators.Add(gen); + } + + public override void CleanUp() + { + base.CleanUp(); + Generators.Clear(); + InputController.Unbind("pause", HandlePause); + Renderer.Empty(); + ActorManager.Empty(); } } }